package com.jrfid.smartcabinet.demo.ui.take_result.adapter

import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseDataBindingHolder
import com.jrfid.smartcabinet.demo.R
import com.jrfid.smartcabinet.demo.databinding.ItemTakeResultBinding
import com.jrfid.smartcabinet.demo.model.TagInfoModel
import kotlin.math.max
import kotlin.math.min

class TakeResultAdapter : BaseQuickAdapter<TagInfoModel, BaseDataBindingHolder<ItemTakeResultBinding>>(R.layout.item_take_result) {

    override fun convert(holder: BaseDataBindingHolder<ItemTakeResultBinding>, item: TagInfoModel) {
        holder.dataBinding?.viewModel = item
    }

    fun remove(epc: String) {
        //删除epc相同的数据
        val index = data.indexOfFirst {
            it.epc == epc
        }
        if (index != -1) {
            removeAt(index)
        }
    }

    override fun addData(model: TagInfoModel) {
        //如果没有匹配的数据，则添加
        if (data.none { it.epc == model.epc }) {
            super.addData(model)
        }
    }
}